#ifndef SIMPLEPROGRESSNOTIFIER_H
#define SIMPLEPROGRESSNOTIFIER_H

#include <QObject>
#include <QTimer>
#include <QColor>

/**
 * 简化的进度通知器
 * Martin Fowler重构：Replace Complex Condition with Simple State
 * Jony Ive设计理念：少即是多，只显示必要信息
 */
class SimpleProgressNotifier : public QObject
{
    Q_OBJECT

public:
    enum ProgressState {
        Idle,           // 空闲
        Preparing,      // 准备
        Processing,     // 处理中
        Completing,     // 完成
        Completed,      // 已完成
        Failed,         // 失败
        Cancelled       // 已取消
    };

    explicit SimpleProgressNotifier(QObject* parent = nullptr);
    ~SimpleProgressNotifier() = default;

    // 状态控制
    void setState(ProgressState state);
    void setProgress(int percentage);
    void reset();

    // 状态查询
    ProgressState getCurrentState() const { return m_currentState; }
    int getCurrentProgress() const { return m_currentProgress; }
    bool isActive() const { return m_currentState != Idle; }

    // UI友好的状态描述
    QString getStateText() const;
    QColor getStateColor() const;

signals:
    void stateChanged(ProgressState newState);
    void progressUpdated(int percentage);
    void UIUpdateRequested(const QString& text, const QColor& color);

private slots:
    void onStateTimeout();

private:
    void emitUIUpdate();

    ProgressState m_currentState;
    int m_currentProgress;
    QString m_lastEmittedText;
    QColor m_lastEmittedColor;

    // 防抖定时器
    QTimer* m_debounceTimer;
    static const int DEBOUNCE_INTERVAL_MS = 200;
};

#endif // SIMPLEPROGRESSNOTIFIER_H